<!--智慧政务-办理指南列表-->
<template>
	<view class="body">
		<view class='search'>
			<view class='search-c'>
				<image class='icon search-icon' src='../../../static/image/zoom.png'></image>
				<input class='search-input' placeholder-class='search-input-p' placeholder='请输入关键字搜索' v-model="key"></input>
			</view>
			<button class="btn" @click="searchData()" hover-class="btn-hover2">搜索</button>
		</view>
		<empty v-if="affairs.length == 0"></empty>
		<view class="list" v-else>
			<view class="listcontent" v-for="(item,index) in affairs" v-on:click="gotoAffairsDetail(item)">
				<view class="list-icon">
					<view>{{item.month < 10 ? "0"+item.month : item.month}}-{{item.day<10?"0"+item.day:item.day}}</view>
					<view style="font-size: 36upx;font-weight: normal;">{{item.year}}</view>
				</view>

				<view class="listtext">
					<text v-if="index < 3" class="new_text">新</text>
					{{item.title}}
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import empty from '@/components/empty.vue'
	export default {
		data() {
			return {
				communityId: this.$api.util.getAreaCode(),
				affairs: [],
				time: '',
				page: 1,
				total: 0,
				key: '',
				loadingType: 'more'
			}
		},
		computed: {
			...mapState(['defaultCommunityId']),
		},
		onLoad() {
			this.getData()
			// this.$api.sysauth.checkLoginAndBindCommunity();
		},
		onReachBottom() {
			if (this.loadingType === 'more') {
				this.page = this.page + 1;
				this.getData()
			}
		},
		components: {
			empty
		},
		methods: {
			//办事指南模糊查询
			getData() {
				let params = {
					"areaCode": this.communityId,
					"tagType": "AFFAIRS",
					"tagName": this.key,
					"articleType": "6",
					"page": this.page,
					"rows": "10"
				}
				this.$api.request.LikeTypeName(params, (res) => {
					console.log(res.body.data.list)
					if (res.body.status.statusCode == "0") {
						let newLists = res.body.data.list
						for (var i = 0; i < newLists.length; i++) {
							let time = new Date(newLists[i].publishTime.replace(/-/g, "/"))
							newLists[i].year = time.getFullYear();
							newLists[i].month = time.getMonth() + 1;
							newLists[i].day = time.getDate();
						};
						this.affairs = this.affairs.concat(newLists);
						let total = res.body.data.total
						if (this.affairs.length >= total) {
							this.loadingType = 'noMore'
						}else{
							this.loadingType = 'more'
						}
					}
				})
			},
			searchData() {
				this.page = 1;
				this.affairs = [];
				this.getData();
			},
			gotoAffairsDetail(item) {
				uni.navigateTo({
					url: '/package_biz/pages/smartaffairs/affairdetail?id=' + item.articleUuid
				})
			}
		}
	}
</script>

<style>
	.body {
		width: 100%;
		height: 100%;
		padding-left: 20upx;
		padding-right: 20upx;
	}

	.search {
		width: 100%;
		height: 80upx;
		padding-top: 10upx;
		background-color: rgba(255, 255, 255, 1);
		/* z-index: 99; */
		transition: all .5s;
		display: flex;
		position: relative;
	}

	.search-c {
		height: 100%;
		position: relative;
		width: 75%;
		margin-right: 1%;
		z-index: 99;
	}

	.search-input {
		background-color: #E9E9E9;
		/* background-color: red; */
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		line-height: 50upx;
		border-radius: 50upx;
		font-size: 24upx;
		transition: all .5s;
		padding: 10upx 30upx 10upx 90upx;
	}

	.search-input-p {
		color: #999;
		width: 100%;
		height: 100%;
		padding: 0 !important;
	}

	.search-input-p-c {
		position: relative;
		top: 50%;
		transform: translateY(-50%);
	}

	.search-icon {
		position: absolute;
		top: 50%;
		left: 30upx;
		right: 30upx;
		transform: translateY(-50%);
		z-index: 999;
	}

	.icon {
		width: 50upx;
		height: 50upx;
		z-index: 999;
		/* #ifdef MP-ALIPAY */
		background-size: 100% 100%;
		/* #endif */
	}

	.search .btn {
		width: 20%;
		background-color: #f1f1f1;
		font-size: 28upx;
		color: #333;
		height: 72upx;
		line-height: 72upx;
	}

	.list {
		width: 100%;
		height: 100%;
		padding-top: 40upx;

	}

	.listcontent {
		width: 100%;
		height: 110upx;
		margin-top: 20upx;
		border-radius: 15upx;
		background-color: #f3f3f3;
		position: relative;
		display: flex;
		justify-content: left;
		align-items: center;

	}

	.list-icon {
		/* position: absolute;
		top: 50%;
		left: 30upx;
		right: 30upx;
		transform: translateY(-50%); */
		font-size: 24upx;
		color: white;
		text-align: center;
		font-weight: lighter;
		margin-right: 8upx;
		z-index: 99;
		padding: 14upx;
		width: 150upx;
		height: 110upx;
		/* border-radius: 25upx; */
		background-color: #5FBCF0;
		border-radius: 15upx 0 0 15upx;
	}

	.new_text {
		/* display: inline-block; */
		color: #E7526C;
		margin-right: 4upx;
		text-align: center;
		font-size: 20upx;
		line-height: 90upx;
		border: 2px solid #E7526C;
		padding: 2upx;
		transition: all .5s;
		border-radius: 6upx;
	}

	.listtext {
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		line-height: 90upx;
		border-radius: 50upx;
		font-size: 30upx;
		font-weight: bold;
		transition: all .5s;
		padding: 10upx 30upx 10upx 6upx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style>
